//等待玩家
waitUntil {count allPlayers > 0};
//刷兵 36分钟 刷3次

private["_player","_level", "_group","_twice"];
as_level = 0;

//初始突击队

[]spawn
{
	private _player_num = ceil(count(call fn_getPlayerRed) / 2);
	if(_player_num < 3) then{_player_num = 3;};
	
	for "_i" from 1 to _player_num do 
	{
		//[asg_1, as_start_pos, 500] spawn fn_createG;
		
		[0, asg_1, as_start_pos, 500, 0, 1] spawn fn_createGN;
		
		sleep 1;
	};
	
	sleep 30;
	if(count(call fn_getPlayerRed) > 2) then
	{
		[0, asg_5, as_start_pos, 1000, 0, 1] spawn fn_createGN;
	};
};

//初始增援
[]spawn
{
	private _player = call fn_getLivePlayer;

	//先刷 玩家数量*0.75
	for "_i" from 1 to (count call fn_getPlayerRed) do{
		[1, floor random 3, getPos _player, 400, 0.75, selectRandom [1, 2, 3], true] spawn fn_createGN; 
		sleep 1;
	};
	
	sleep 600 * Param_EnemySupportTime;
	{
		if((_x distance2D as_start_pos) < 320) exitWith
		{
			[1, 1, getPos _player, 600, 1.5, 6, true] spawn fn_createGN; 
			
			sleep 1;
			[0, selectRandom asg_normal, getPos _x, 0, 0, 1] spawn fn_createGN;
		};
	}forEach (call fn_getPlayerRed);
	
	sleep 1800 * Param_EnemySupportTime;
	{
		if((_x distance2D as_start_pos) < 320) exitWith
		{
			[1, 1, getPos _player, 600, 1.8, 6, true] spawn fn_createGN; 

			sleep 1;
			[0, selectRandom asg_normal, getPos _x, 0, 0, 1] spawn fn_createGN;
			sleep 1;
			[0, selectRandom asg_normal, getPos _x, 0, 0, 1] spawn fn_createGN;
		};
	}forEach (call fn_getPlayerRed);
};

//位置部队
//所有位置
//["Mount","CityCenter","Airport","NameMarine","NameCityCapital","NameCity","NameVillage","NameLocal","Hill","ViewPoint","RockArea","BorderCrossing","VegetationBroadleaf","VegetationFir","VegetationPalm","VegetationVineyard","fakeTown","Area","Flag","Invisible","HistoricalSite","CivilDefense","CulturalProperty","DangerousForces","SafetyZone","HandDrawnCamp"]

private _pos = [[],[],[],[],[],[]];


//山
{
	private _h = getTerrainHeightASL position _x;
	if(_h > 50)then{
		//每50米，增高等级
		private _level = round(_h / 50);
		if(_level > 5) then{_level = 5};
		private _type = [2,3];if(_level > 3) then{_type = [0,1]};
		(_pos select _level) pushBack [position _x, selectRandom _type, (6 - _level) * 0.25];
	}
} forEach nearestLocations [[worldSize / 2, worldSize / 2], ["Mount"], worldSize / 2 * 1.414];


//City
{
	(_pos select (selectRandom[0,1,2,3,4,5,6])) pushBack [position _x, selectRandom[0,1,2,3], 0.75];
	if(random 100 < as_num_g0) then{
		[0, selectRandom asg_easy, position _x, 10] spawn fn_createGN;
	};
} forEach nearestLocations [[worldSize / 2, worldSize / 2], ["NameLocal"], worldSize / 2 * 1.414];

{
	(_pos select (selectRandom[0,1,2])) pushBack [position _x, selectRandom[0,1,2,3], 0.5];
} forEach nearestLocations [[worldSize / 2, worldSize / 2], ["NameVillage"], worldSize / 2 * 1.414];

{
	(_pos select (selectRandom[2,3,4])) pushBack [position _x, selectRandom[1,2,3], 1.0];
	if(random 100 < as_num_g0) then{
		[0, selectRandom asg_normal, position _x, 10] spawn fn_createGN;
	};
	
	if(Param_Plane >= 1 && {random 100 < 20}) then{
		[0, asg_10, position _x, 10] spawn fn_createGN;
	};
} forEach nearestLocations [[worldSize / 2, worldSize / 2], ["NameCity"], worldSize / 2 * 1.414];

{
	(_pos select (selectRandom[4,5])) pushBack [position _x, selectRandom[2,3], 1.5];
	
	if(random 100 < 30) then{
		[0, asg_10, position _x, 10] spawn fn_createGN;
	};
	
	
	if(Param_Plane >= 2 && {random 100 < 75}) then{
		[0, selectRandom[asg_21, asg_22], position _x, 10] spawn fn_createGN;
	};
	
} forEach nearestLocations [[worldSize / 2, worldSize / 2], ["NameCityCapital"], worldSize / 2 * 1.414];

{
	(_pos select 2) pushBack [position _x, 3, 1.0];
} forEach nearestLocations [[worldSize / 2, worldSize / 2], ["NameMarine"], worldSize / 2 * 1.414];

private _pos_2 = [[],[],[],[],[],[]];
for "_i" from 0 to 5 do
{
	//太近的剔除
	{
		private _y = _x select 0;
		private _close = false;
		{
			if((_x select 0) distance2D _y < 1200)exitWith{_close = true};
		}forEach (_pos_2 select _i);
		
		if(!_close)then{(_pos_2 select _i) pushBack _x};
	}forEach (_pos select _i);
	

	//普通部队
	{
		if(random 100 < as_num_g1) then{
			[1, _x select 1, _x select 0, 0, _x select 2, _i + 1, true] spawn fn_createGN; 
		};
	}forEach (_pos_2 select _i);
};

//

/*
_twice = 0;
while{true} do
{
	waitUntil{sleep 10;call fn_canSpawnAI};
	
	if(as_level < 4) then
	{
		_level = selectRandom [1, 2];
	}
	else
	{
		if(as_level < 8) then	
		{
			_level = selectRandom [1, 2, 3, 4];
		}
		else
		{
			if(as_level < 12) then	
			{
				_level = selectRandom [2, 3, 4];
			}
			else
			{
				if(as_level < 15) then	
				{
					_level = selectRandom [3, 4];
				}
				else
				{
					_level = selectRandom [3, 4, 5];
				};
			};
		};
	};
	
	
	//1
	_player = call fn_getLivePlayer;

	_group = [getPos _player, call fn_aiNum, _level, 1000, floor random 4, true] call fn_createGroup;
	[_group, _player] call fn_addWaypoint;
	[_group] spawn fn_controlGroup;
	sleep as_debug_spawn_dt;
	
	//2
	_player = call fn_getLivePlayer;

	_group = [getPos _player, call fn_aiNum, _level, 1000, floor random 4, true] call fn_createGroup;
	[_group, _player] call fn_addWaypoint;
	[_group] spawn fn_controlGroup;
	sleep as_debug_spawn_dt;
	
	//3
	_player = call fn_getLivePlayer;

	_group = [getPos _player, call fn_aiNum, _level, 1000, floor random 4, true] call fn_createGroup;
	[_group, _player] call fn_addWaypoint;
	[_group] spawn fn_controlGroup;
	sleep as_debug_spawn_dt;

	
	
	
	//搜索队 36分钟一次（s2翻倍）
	_player = call fn_getLivePlayer;
	
	if(_level < 4) then
	{
		[getPos _player]spawn fn_createS1;
	}
	else
	{
		if(_twice == 0) then
		{
			_twice = _twice + 1;
		}
		else
		{
			[getPos _player]spawn fn_createS2;
			_twice = 0;
		};
		
	};


};

*/